@extends('layouts.default')
@section('content') 
<div class="box">
    <header>
        <div class="icons">
            <i class="fa fa-table"></i>
        </div>
        <h5>{{ Lang::get('messages.maintenance_head') }}</h5>
        <div class="toolbar"> 
            {{ Helpers\Helper::fa_link_to_action('glyphicon glyphicon-plus',
                                        'MaintenanceController@create',Lang::get('messages.add_btn'),
                                        $car_id, array( 
                            'class'=>'btn btn-success btn-sm btn-round')) 
            }}                            
        </div>
    </header><br/>
    <table id="dataTable"  style="width:100%" class="table table-bordered table-condensed table-hover table-striped">
        <thead style="width:100%">
            <tr>
                <th>{{Lang::get('messages.process')}}</th>
                <th>{{Lang::get('messages.milage')}}</th>
                <th>{{Lang::get('messages.date')}}</th>
                <th>{{Lang::get('messages.next_milage')}}</th>
                <th>{{Lang::get('messages.next_date')}}</th>                      
                <th>{{Lang::get('messages.nr_invoice')}}</th>
                <th>{{Lang::get('messages.user')}}</th>
                <th>{{Lang::get('messages.status')}}</th> 
                <th>{{Lang::get('messages.action')}}</th>
            </tr>
        </thead>
        <tbody  style="width:100%">                          
            @foreach ($maintenance as $m)
            <tr> 
                <td>{{ Lang::get('processes.'.$m->process) }}</td>    
                <td>{{ $m->milage}}</td>  
                <td>{{ $m->maintenance_date}}</td> 
                <td>{{ $m->km_due + $m->maint_milage}}</td>
                <td>{{ Helpers\Helper::next_date($m->maintenance_date, $m->month_due)}}</td>                            
                <td>{{ $m->nr_invoice}}</td>
                <td>{{ $m->first_name}}</td>  
                <td> @if(
                    ((Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) >= 0)
                    && (Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) <= 4))
                    && ((Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) >= 0) 
                    && (Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) <= 4))
                    )  
                    <i class="fa fa-check-circle fa-lg" style="color:#42b142" 
                           title="{{ Lang::get('messages.success_tltp_maint') }}"></i>
                    @elseif(
                    ((Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) >= 0) 
                    && (Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) <= 4))
                    && ((Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) >= 5) 
                    && (Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) <= 20))
                    )  
                     <i class="fa fa-exclamation-circle fa-lg" style="color:#ec971f" 
                           title="{{Lang::get('messages.warning_tltp_maint') }}"></i>
                
                    @elseif(
                    ((Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) >= 0) 
                    && (Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) <= 4))
                    && ((Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) >= 21))
                    )  
                     <i class="fa fa-exclamation-circle fa-lg" style="color:#c00" 
                           title="{{Lang::get('messages.danger_tltp_maint') }}"></i>

                    @elseif (
                    ((Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) >= 5) 
                    && (Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) <= 20))
                    && ((Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) >= 0) 
                    && (Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) <= 4))
                    )
                     <i class="fa fa-exclamation-circle fa-lg" style="color:#ec971f" 
                           title="{{Lang::get('messages.warning_tltp_maint') }}"></i>
                    @elseif (
                    ((Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) >= 5) 
                    && (Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) <= 20))
                    && ((Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) >= 5) 
                    && (Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) <= 20))
                    )
                    <i class="fa fa-exclamation-circle fa-lg" style="color:#ec971f" 
                           title="{{Lang::get('messages.warning_tltp_maint') }}"></i>
                    @elseif (
                    ((Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) >= 5) 
                    && (Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) <= 20))
                    && ((Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) >= 21))
                    )
                      <i class="fa fa-exclamation-circle fa-lg" style="color:#c00" 
                           title="{{Lang::get('messages.danger_tltp_maint') }}"></i>          

                    @elseif(
                    ((Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) >= 21))
                    && ((Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) >= 21))
                    )
                      <i class="fa fa-exclamation-circle fa-lg" style="color:#c00" 
                           title="{{Lang::get('messages.danger_tltp_maint') }}"></i>   

                    @elseif(
                    ((Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) >= 21))
                    && ((Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) >= 0) 
                    && (Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) <= 4))
                    )
                    <i class="fa fa-exclamation-circle fa-lg" style="color:#c00" 
                           title="{{Lang::get('messages.danger_tltp_maint') }}"></i>  

                    @elseif(
                    ((Helpers\Helper::status_maintenance($m->milage, $m->km_due, $m->maint_milage) >= 21))
                    && ((Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) >= 5) 
                    && (Helpers\Helper::status_date($current_date, $m->month_due, $m->maintenance_date) <= 20))
                    )
                    <i class="fa fa-exclamation-circle fa-lg" style="color:#c00" 
                           title="{{Lang::get('messages.danger_tltp_maint') }}"></i>  
                    @endif                                 
                </td> 
                <td>{{ Helpers\Helper::fa_link_to_action('glyphicon glyphicon-edit',
                                'MaintenanceController@edit',Lang::get('messages.edit_btn'),$m->maint_id, array( 
                            'class'=>'btn btn-success btn-xs btn-round')) 
                    }} </td>
            </tr>                            
            @endforeach 
            @foreach ($processes as $p)
            @if (Helpers\Helper::array_value($p->id, $car_process)== 0) 
            <tr>
                <td class="text-danger">{{ Lang::get('processes.'.$p->process)}} {{ Lang::get('messages.missing')}}</td> 
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>   
                <td></td> 
            </tr>
            @endif
            @endforeach
        </tbody>
    </table>
</div>
{{
                link_to_action('MaintenanceController@maintenance_history', 
                Lang::get('messages.maintenance_history'), array('id'=>$car_id))
}}                       
@stop
